

import java.awt.*;

public class MapBottom {//底层地图类，用于绘制游戏相关基础组件

    BottomRay bottomRay = new BottomRay();
    BottomNum bottomNum = new BottomNum();
    {
        bottomRay.newRay();
        bottomNum.newNum();
    }//生成地雷和数字

    void reGame(){//重置游戏
        for (int i = 1; i <=GameUtil.Width ; i++) {
            for (int j = 1; j <=GameUtil.Height ; j++) {
                GameUtil.ElementBottom[i][j]=0;
            }
        }
        bottomRay.newRay();
        bottomNum.newNum();
    }
   
    void paintSelf(Graphics g){//绘制方法
        g.setColor(Color.red);
       
        for (int i = 0; i <= GameUtil.Width; i++) {//画竖线
            g.drawLine(GameUtil.Offset + i * GameUtil.SquareLength,
                    3*GameUtil.Offset,
                    GameUtil.Offset+i*GameUtil.SquareLength,
                    3*GameUtil.Offset+GameUtil.Height*GameUtil.SquareLength);
        }
        
        for (int i = 0; i <=GameUtil.Height; i++){//画横线
            g.drawLine(GameUtil.Offset,
                    3*GameUtil.Offset+i*GameUtil.SquareLength,
                    GameUtil.Offset+GameUtil.Width*GameUtil.SquareLength,
                    3*GameUtil.Offset+i*GameUtil.SquareLength);
        }
        for (int i = 1; i <= GameUtil.Width ; i++) {
            for (int j = 1; j <= GameUtil.Height; j++) {
                
                if (GameUtil.ElementBottom[i][j] == -1) {//将雷的图片绘制到底层地图上
                    g.drawImage(GameUtil.lei,
                            GameUtil.Offset + (i - 1) * GameUtil.SquareLength + 1,
                            GameUtil.Offset * 3 + (j - 1) * GameUtil.SquareLength + 1,
                            GameUtil.SquareLength - 2,
                            GameUtil.SquareLength - 2,
                            null);
                }
                
                if (GameUtil.ElementBottom[i][j] >=0) {//将数字的图片绘制到底层地图上
                    g.drawImage(GameUtil.images[GameUtil.ElementBottom[i][j]],
                            GameUtil.Offset + (i - 1) * GameUtil.SquareLength + 15,
                            GameUtil.Offset * 3 + (j - 1) * GameUtil.SquareLength + 5,
                            null);
                }

            }
        }

        GameUtil.drawWord(g,""+(GameUtil.MineNumber-GameUtil.FlagNumber),
                GameUtil.Offset,
                2*GameUtil.Offset,30,Color.red);//在左上角显示剩余地雷数
        GameUtil.drawWord(g,""+(GameUtil.EndTime-GameUtil.StartTime)/1000,
                GameUtil.Offset + GameUtil.SquareLength*(GameUtil.Width-1),
                2*GameUtil.Offset,30,Color.red);//在右上角显示进行该游戏所用的时间（秒）
        
        switch (GameUtil.state){
            case 0:
                GameUtil.EndTime=System.currentTimeMillis();
                g.drawImage(GameUtil.face,
                        GameUtil.Offset + GameUtil.SquareLength * (GameUtil.Width/2),
                        GameUtil.Offset,
                        null);//游戏正在进行，最上面显示一个表情图片
                break;
            case 1:
                g.drawImage(GameUtil.win,
                        GameUtil.Offset + GameUtil.SquareLength * (GameUtil.Width/2),
                        GameUtil.Offset,
                        null);//游戏通关，表情变为笑脸
                break;
            case 2:
                g.drawImage(GameUtil.over,
                        GameUtil.Offset + GameUtil.SquareLength * (GameUtil.Width/2),
                        GameUtil.Offset,
                        null);//游戏失败，表情变为哭脸
                break;

                default:
        }
    }
}
